/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.main;

import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import edu.mobbuzz.page.authorization.LoginPage;
import edu.mobbuzz.page.menu.MainMenu;
import javax.microedition.midlet.*;

/**
 * @author dailicious
 */
public class Mobbuzz extends MIDlet implements ActionListener {
    private Form mainForm;

    public void startApp() {
        Display.init(this);

        mainForm = new Form();    
        try {
            Resources r = Resources.open("/mobbuzz.res");
            UIManager.getInstance().setThemeProps(r.getTheme("mobbuzz"));

        } catch (java.io.IOException e) {
            e.printStackTrace();
        }

        try{
            LoginPage loginPage = new LoginPage();
            mainForm = loginPage.showPage();
            mainForm.setCommandListener(this);
            mainForm.show();

        }catch(Exception e){
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        
    }
   
    public void actionPerformed(ActionEvent ev) {
       if(ev.getCommand().getCommandName().equals("Exit")){
            destroyApp(true);
            notifyDestroyed();
        }else if(ev.getCommand().getCommandName().equals("Go Offline")){
            MainMenu inboxPage = new MainMenu();
            inboxPage.setExitCmd(mainForm.getBackCommand());
            inboxPage.setActionlistener(this);
            inboxPage.showPage();

        }else if(ev.getCommand().getCommandName().equals("Go Online")){
            mainForm.show();
        }
    }
}
